home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / fd.s5 / mycat.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  629b  |  36 lines

  1. /*
  2.  * Catenate one or more files to standard output.
  3.  * If no files are specified, default to standard input.
  4.  */
  5.  
  6. #define    BUFFSIZE    4096
  7.  
  8. main(argc, argv)
  9. int    argc;
  10. char    *argv[];
  11. {
  12.     int        fd, i, n;
  13.     char        buff[BUFFSIZE];
  14.     extern char    *pname;
  15.  
  16.     pname = argv[0];
  17.     argv++; argc--;
  18.  
  19.     fd = 0;        /* default to stdin if no arguments */
  20.     i = 0;
  21.     do {
  22.         if (argc > 0 && (fd = my_open(argv[i], 0)) < 0) {
  23.             err_ret("can't open %s", argv[i]);
  24.             continue;
  25.         }
  26.  
  27.         while ( (n = read(fd, buff, BUFFSIZE)) > 0)
  28.             if (write(1, buff, n) != n)
  29.                 err_sys("write error");
  30.         if (n < 0)
  31.             err_sys("read error");
  32.  
  33.     } while (++i < argc);
  34.     exit(0);
  35. }
  36.